package com.geo.content.entity;

import com.baomidou.mybatisplus.annotation.*;
import lombok.Data;
import lombok.Builder;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Size;
import java.time.LocalDateTime;
import java.util.List;

/**
 * 多模态内容实体类
 * 
 * @author GEO Team
 * @version 1.0
 */
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@TableName("content_multimodal")
public class MultimodalContent {
    
    // 手动添加builder方法以解决编译问题
    public static MultimodalContentBuilder builder() {
        return new MultimodalContentBuilder();
    }
    
    public static class MultimodalContentBuilder {
        private String id;
        private String merchantId;
        private String keywordId;
        private String title;
        private String description;
        private ContentType contentType;
        private ContentStatus status;
        private String textContent;
        private String tags;
        private String category;
        private String language;
        private Double qualityScore;
        private Double seoScore;
        private String publishPlatforms;
        private PublishStatus publishStatus;
        private LocalDateTime publishedAt;
        private Long viewCount;
        private Long likeCount;
        private Long shareCount;
        private Long commentCount;
        private String metadata;
        private Integer version;
        private String parentId;
        private String remark;
        private LocalDateTime createdAt;
        private LocalDateTime updatedAt;
        private String createdBy;
        private String updatedBy;
        private Integer deleted;
        
        public MultimodalContentBuilder id(String id) {
            this.id = id;
            return this;
        }
        
        public MultimodalContentBuilder merchantId(String merchantId) {
            this.merchantId = merchantId;
            return this;
        }
        
        public MultimodalContentBuilder keywordId(String keywordId) {
            this.keywordId = keywordId;
            return this;
        }
        
        public MultimodalContentBuilder title(String title) {
            this.title = title;
            return this;
        }
        
        public MultimodalContentBuilder description(String description) {
            this.description = description;
            return this;
        }
        
        public MultimodalContentBuilder contentType(ContentType contentType) {
            this.contentType = contentType;
            return this;
        }
        
        public MultimodalContentBuilder status(ContentStatus status) {
            this.status = status;
            return this;
        }
        
        public MultimodalContentBuilder textContent(String textContent) {
            this.textContent = textContent;
            return this;
        }
        
        public MultimodalContentBuilder tags(String tags) {
            this.tags = tags;
            return this;
        }
        
        public MultimodalContentBuilder category(String category) {
            this.category = category;
            return this;
        }
        
        public MultimodalContentBuilder language(String language) {
            this.language = language;
            return this;
        }
        
        public MultimodalContentBuilder qualityScore(Double qualityScore) {
            this.qualityScore = qualityScore;
            return this;
        }
        
        public MultimodalContentBuilder seoScore(Double seoScore) {
            this.seoScore = seoScore;
            return this;
        }
        
        public MultimodalContentBuilder publishPlatforms(String publishPlatforms) {
            this.publishPlatforms = publishPlatforms;
            return this;
        }
        
        public MultimodalContentBuilder publishStatus(PublishStatus publishStatus) {
            this.publishStatus = publishStatus;
            return this;
        }
        
        public MultimodalContentBuilder publishedAt(LocalDateTime publishedAt) {
            this.publishedAt = publishedAt;
            return this;
        }
        
        public MultimodalContentBuilder viewCount(Long viewCount) {
            this.viewCount = viewCount;
            return this;
        }
        
        public MultimodalContentBuilder likeCount(Long likeCount) {
            this.likeCount = likeCount;
            return this;
        }
        
        public MultimodalContentBuilder shareCount(Long shareCount) {
            this.shareCount = shareCount;
            return this;
        }
        
        public MultimodalContentBuilder commentCount(Long commentCount) {
            this.commentCount = commentCount;
            return this;
        }
        
        public MultimodalContentBuilder metadata(String metadata) {
            this.metadata = metadata;
            return this;
        }
        
        public MultimodalContentBuilder version(Integer version) {
            this.version = version;
            return this;
        }
        
        public MultimodalContentBuilder parentId(String parentId) {
            this.parentId = parentId;
            return this;
        }
        
        public MultimodalContentBuilder remark(String remark) {
            this.remark = remark;
            return this;
        }
        
        public MultimodalContentBuilder createdAt(LocalDateTime createdAt) {
            this.createdAt = createdAt;
            return this;
        }
        
        public MultimodalContentBuilder updatedAt(LocalDateTime updatedAt) {
            this.updatedAt = updatedAt;
            return this;
        }
        
        public MultimodalContentBuilder createdBy(String createdBy) {
            this.createdBy = createdBy;
            return this;
        }
        
        public MultimodalContentBuilder updatedBy(String updatedBy) {
            this.updatedBy = updatedBy;
            return this;
        }
        
        public MultimodalContentBuilder deleted(Integer deleted) {
            this.deleted = deleted;
            return this;
        }
        
        public MultimodalContent build() {
            MultimodalContent content = new MultimodalContent();
            content.id = this.id;
            content.merchantId = this.merchantId;
            content.keywordId = this.keywordId;
            content.title = this.title;
            content.description = this.description;
            content.contentType = this.contentType;
            content.status = this.status;
            content.textContent = this.textContent;
            content.tags = this.tags;
            content.category = this.category;
            content.language = this.language;
            content.qualityScore = this.qualityScore;
            content.seoScore = this.seoScore;
            content.publishPlatforms = this.publishPlatforms;
            content.publishStatus = this.publishStatus;
            content.publishedAt = this.publishedAt;
            content.viewCount = this.viewCount;
            content.likeCount = this.likeCount;
            content.shareCount = this.shareCount;
            content.commentCount = this.commentCount;
            content.metadata = this.metadata;
            content.version = this.version;
            content.parentId = this.parentId;
            content.remark = this.remark;
            content.createdAt = this.createdAt;
            content.updatedAt = this.updatedAt;
            content.createdBy = this.createdBy;
            content.updatedBy = this.updatedBy;
            content.deleted = this.deleted;
            return content;
        }
    }
    
    /**
     * 内容ID
     */
    @TableId(value = "id", type = IdType.ASSIGN_ID)
    private String id;
    
    /**
     * 商家ID
     */
    @TableField("merchant_id")
    private String merchantId;
    
    /**
     * 关键词ID
     */
    @TableField("keyword_id")
    private String keywordId;
    
    /**
     * 内容标题
     */
    @NotBlank(message = "内容标题不能为空")
    @Size(max = 200, message = "内容标题长度不能超过200个字符")
    @TableField("title")
    private String title;
    
    /**
     * 内容描述
     */
    @TableField("description")
    private String description;
    
    /**
     * 内容类型
     */
    @TableField("content_type")
    private ContentType contentType;
    
    /**
     * 内容状态
     */
    @TableField("status")
    private ContentStatus status;
    
    /**
     * 文本内容
     */
    @TableField("text_content")
    private String textContent;
    
    /**
     * 内容标签（JSON格式）
     */
    @TableField("tags")
    private String tags;
    
    /**
     * 内容分类
     */
    @TableField("category")
    private String category;
    
    /**
     * 内容语言
     */
    @TableField("language")
    private String language;
    
    /**
     * 内容质量评分
     */
    @TableField("quality_score")
    private Double qualityScore;
    
    /**
     * SEO评分
     */
    @TableField("seo_score")
    private Double seoScore;
    
    /**
     * 发布平台（JSON格式）
     */
    @TableField("publish_platforms")
    private String publishPlatforms;
    
    /**
     * 发布状态
     */
    @TableField("publish_status")
    private PublishStatus publishStatus;
    
    /**
     * 发布时间
     */
    @TableField("published_at")
    private LocalDateTime publishedAt;
    
    /**
     * 浏览次数
     */
    @TableField("view_count")
    private Long viewCount;
    
    /**
     * 点赞次数
     */
    @TableField("like_count")
    private Long likeCount;
    
    /**
     * 分享次数
     */
    @TableField("share_count")
    private Long shareCount;
    
    /**
     * 评论次数
     */
    @TableField("comment_count")
    private Long commentCount;
    
    /**
     * 内容元数据（JSON格式）
     */
    @TableField("metadata")
    private String metadata;
    
    /**
     * 版本号
     */
    @TableField("version")
    private Integer version;
    
    /**
     * 父内容ID（用于版本管理）
     */
    @TableField("parent_id")
    private String parentId;
    
    /**
     * 备注
     */
    @TableField("remark")
    private String remark;
    
    /**
     * 创建时间
     */
    @TableField(value = "created_at", fill = FieldFill.INSERT)
    private LocalDateTime createdAt;
    
    /**
     * 更新时间
     */
    @TableField(value = "updated_at", fill = FieldFill.INSERT_UPDATE)
    private LocalDateTime updatedAt;
    
    /**
     * 创建者ID
     */
    @TableField("created_by")
    private String createdBy;
    
    /**
     * 更新者ID
     */
    @TableField("updated_by")
    private String updatedBy;
    
    /**
     * 逻辑删除标志
     */
    @TableLogic
    @TableField("deleted")
    private Integer deleted;
    
    /**
     * 内容类型枚举
     */
    public enum ContentType {
        TEXT("text", "文本"),
        IMAGE("image", "图片"),
        VIDEO("video", "视频"),
        AUDIO("audio", "音频"),
        DOCUMENT("document", "文档"),
        MIXED("mixed", "混合内容");
        
        private final String code;
        private final String description;
        
        ContentType(String code, String description) {
            this.code = code;
            this.description = description;
        }
        
        public String getCode() {
            return code;
        }
        
        public String getDescription() {
            return description;
        }
        
        public static ContentType fromCode(String code) {
            for (ContentType type : values()) {
                if (type.code.equals(code)) {
                    return type;
                }
            }
            return TEXT;
        }
    }
    
    /**
     * 内容状态枚举
     */
    public enum ContentStatus {
        DRAFT("draft", "草稿"),
        REVIEW("review", "审核中"),
        APPROVED("approved", "已审核"),
        REJECTED("rejected", "已拒绝"),
        PUBLISHED("published", "已发布"),
        ARCHIVED("archived", "已归档");
        
        private final String code;
        private final String description;
        
        ContentStatus(String code, String description) {
            this.code = code;
            this.description = description;
        }
        
        public String getCode() {
            return code;
        }
        
        public String getDescription() {
            return description;
        }
        
        public static ContentStatus fromCode(String code) {
            for (ContentStatus status : values()) {
                if (status.code.equals(code)) {
                    return status;
                }
            }
            return DRAFT;
        }
    }
    
    /**
     * 发布状态枚举
     */
    public enum PublishStatus {
        NOT_PUBLISHED("not_published", "未发布"),
        PUBLISHING("publishing", "发布中"),
        PUBLISHED("published", "已发布"),
        PUBLISH_FAILED("publish_failed", "发布失败"),
        PARTIAL_PUBLISHED("partial_published", "部分发布");
        
        private final String code;
        private final String description;
        
        PublishStatus(String code, String description) {
            this.code = code;
            this.description = description;
        }
        
        public String getCode() {
            return code;
        }
        
        public String getDescription() {
            return description;
        }
        
        public static PublishStatus fromCode(String code) {
            for (PublishStatus status : values()) {
                if (status.code.equals(code)) {
                    return status;
                }
            }
            return NOT_PUBLISHED;
        }
    }
    
    /**
     * 检查内容是否可编辑
     * @return 是否可编辑
     */
    public boolean isEditable() {
        return status == ContentStatus.DRAFT || status == ContentStatus.REJECTED;
    }
    
    /**
     * 检查内容是否可发布
     * @return 是否可发布
     */
    public boolean isPublishable() {
        return status == ContentStatus.APPROVED;
    }
    
    /**
     * 检查内容是否已发布
     * @return 是否已发布
     */
    public boolean isPublished() {
        return publishStatus == PublishStatus.PUBLISHED || publishStatus == PublishStatus.PARTIAL_PUBLISHED;
    }
    
    // 手动添加getter和setter方法以解决编译问题
    public String getId() {
        return id;
    }
    
    public String getMerchantId() {
        return merchantId;
    }
    
    public String getTitle() {
        return title;
    }
    
    public String getDescription() {
        return description;
    }
    
    public Long getViewCount() {
        return viewCount;
    }
    
    public void setUpdatedAt(LocalDateTime updatedAt) {
        this.updatedAt = updatedAt;
    }
    
    // 添加更多缺失的getter方法
    public ContentType getContentType() {
        return contentType;
    }
    
    public ContentStatus getStatus() {
        return status;
    }
    
    public Double getQualityScore() {
        return qualityScore;
    }
    
    public LocalDateTime getCreatedAt() {
        return createdAt;
    }
    
    public LocalDateTime getUpdatedAt() {
        return updatedAt;
    }
    
    // 添加缺失的setter方法
    public void setTitle(String title) {
        this.title = title;
    }
    
    public void setDescription(String description) {
        this.description = description;
    }
}